<extend name='./Base' />
<block name='admin-content-body'>

<div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">文章回收站</strong> / <small>Recycle</small></div>
      </div>

      <hr>

      <div class="am-g">
      <form action="{:U('__ACTION__')}" method="get">
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-form-group">
            <select data-am-selected="{btnSize: 'sm'}" name="categoryID">
              <option value=" ">所有类别</option>
              <foreach name='categories' item='v'>
              <option value="{$v['id']}" <if condition="I('get.categoryID') eq $v['id']">selected='selected'</if>>{$v['category']}</option>
              </foreach>
            </select>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" name="title" value="<?php echo $_GET['title'];?>">
          <span class="am-input-group-btn">
            <button type="submit" class="am-btn am-btn-default" type="button">搜索</button>
          </span>
          </div>
        </div>
        </form>
      </div>

      <div class="am-g">
        <div class="am-u-sm-12">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
              <tr>
                <th class="table-id">ID</th>
                <th class="table-title">标题</th>
                <th class="table-type">分类</th>
                <th class="table-type">查看次数</th>
                <th class="table-type">点赞次数</th>
                <th class="table-date am-hide-sm-only">创建日期</th>
                <th class="table-date am-hide-sm-only">修改日期</th>
                <th class="table-set">操作</th>
              </tr>
              </thead>
              <tbody>
                <foreach name="articles" item='a'>
              <tr id="{$a['id']}_article">
                <td>{$a['id']}</td>
                <td><a href="{:U('/home/index/article/id/'.$a['id'])}" target="__blank">{$a['title']}</a></td>
                <td>{$a['category']}</td>
                <td>{$a['views']}</td>
                <td>{$a['likes']}</td>
                <td class="am-hide-sm-only">{$a['create_time']|date='Y-m-d H:i:s',###}</td>
                <td class="am-hide-sm-only">{$a['update_time']|date='Y-m-d H:i:s',###}</td>
                <td>
                  <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                      <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="recover({$a['id']})"><span class="am-icon-pencil-square-o"></span> 还原</button>
                      <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="deletea({$a['id']})"><span class="am-icon-trash-o"></span> 删除</button>
                    </div>
                  </div>
                </td>
              </tr>
             </foreach>
              </tbody>
            </table>
            <!-- <div class="am-cf"> -->
              <div class="am-fr">
                {$pager}
              </div>
            <!-- </div> -->
        </div>

      </div>
    </div>

</block>

<block name="js">
	<script type="text/javascript">
  function deletea(id) {
      layer.confirm('确定要删除？不可恢复！', {
        btn: ['确定','取消']
      },function(){
        $.post('{:U("articles/deletea")}',{'id':id},function(res){
          if(res.status){
            $("#"+id+"_article").remove();
            layer.msg(res.msg);
          }else{
            layer.alert(res.msg,{icon:5});
          }
        });
    },function(){})
   }
   function recover(id) {
      $.post('{:U("articles/recovery")}',{'id':id},function(res){
        if(res.status){
          $("#"+id+"_article").remove();
          layer.msg(res.msg);
        }else{
          layer.alert(res.msg,{icon:5});
        }
      })
   }
  </script>
</block>